package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;

import java.util.*;

/**
 * Created by Student on 26.08.2014.
 */
public class BankReport {
    public static int getNumOfCustomers (Bank bank){
       return bank.getClients().size();
    }

    private static Set <Account> getAllAccounts(Bank bank){
        Set <Account> allAccounts=new HashSet<>();
        for (Client client: bank.getClients()){
            allAccounts.addAll(client.getAccounts());
        }
        return allAccounts;

    }
    public static int getNumOfAccounts (Bank bank){

        return  getAllAccounts(bank).size();
    }
    public static SortedSet <Account> getAccountsSortedBySum (Bank bank){

        TreeSet s = new TreeSet<Account>(new Comparator<Account>() {
            @Override
            public int compare(Account o1, Account o2) {
                return (int)Math.round((o1.getBalance() - o2.getBalance())/Integer.MAX_VALUE);
            }
        });
        s.add(getAllAccounts(bank));
        return Collections.unmodifiableSortedSet(s);

    }
    public static Map<Client, Set <Account> > getCustomerAccount(Bank bank){
        Map<Client, Set <Account> > custAccounts=new HashMap();
        for (Client client:bank.getClients()){
            custAccounts.put(client, client.getAccounts());
        }
        return custAccounts;
    }

}
